﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TimeTravel.XnaLibrary.UI
{
	/// <summary>
	/// Represents a label control used for drawing text at the screen.
	/// </summary>
	public class Label : TextContainer
	{
		/// <summary>
		/// Gets or sets the text of the label.
		/// </summary>
		public override string Text
		{
			get { return base.Text; }
			set 
			{ 
				base.Text = value;
				Location.Width = (int)TextSize.X;
				Location.Height = (int)TextSize.Y;
			}
		}

		/// <summary>
		/// Gets or sets the position to place the label at.
		/// </summary>
		public Point Position
		{
			get { return Location.Location; }
			set { Location.Location = value; }
		}

		/// <summary>
		/// Initializes a new Label instance with the specified font.
		/// </summary>
		/// <param name="font">The text`s font.</param>
		public Label(SpriteFont font)
		{
			Font = font;
		}

		/// <summary>
		/// Draws the label using the specified SpriteBatch. SpriteBatch.Begin must have been called prior to calling this method.
		/// </summary>
		/// <param name="spriteBatch">The sprite batch to draw with.</param>
		public override void Draw(SpriteBatch spriteBatch)
		{	
			if (IsEnabled)
			{
				spriteBatch.DrawString(Font, Text, new Vector2(Position.X, Position.Y), TextColor);
			}
			else
			{	
				Color newColor = TextColor * 0.5f;
				newColor.A = 255;
				spriteBatch.DrawString(Font, Text, new Vector2(Position.X, Position.Y), newColor);
			}
		}
	}
}
